﻿using Basic.HrDAL;
using Basic.HrModel.DB;
using Basic.HrRemoteModel.EmpFile.Model;
using WeDonekRpc.Helper;

namespace Basic.HrCollect.Impl
{
    internal class EmpSelfFileCollect : IEmpSelfFileCollect
    {
        private readonly IEmpSelfFileDAL _Service;

        public EmpSelfFileCollect ( IEmpSelfFileDAL service )
        {
            this._Service = service;
        }
        public void Delete ( DBEmpSelfFileList file )
        {
            this._Service.Delete(file.Id);
        }
        public Result[] Gets<Result> ( long empId, string classtify ) where Result : class, new()
        {
            return this._Service.Gets<Result>(a => a.EmpId == empId && a.Classify == classtify);
        }
        public DBEmpSelfFileList Get ( long id )
        {
            return this._Service.Get(id);
        }
        public long Add ( EmpSelfFileAdd add )
        {
            if ( this._Service.IsExists(a => a.EmpId == add.EmpId && a.FileId == add.FileId) )
            {
                throw new ErrorException("hr.emp.file.repeat");
            }
            return this._Service.Add(add);
        }

        public Result FindLast<Result> ( long empId, string classtify ) where Result : class, new()
        {
            return this._Service.Get<Result>(a => a.EmpId == empId && a.Classify == classtify, "AddTime desc");
        }
    }
}
